<?php

/**
 * JingYao-backend
 *
 * @link     https://gitee.com/wang-zhihui-release/jingyao-backend
 * @apiDocument https://gitee.com/wang-zhihui-release/jingyao-backend/wikis/
 */

namespace App\Http\Resources;

use App\Enums\EducationEnum;
use App\Enums\MaritalStatusEnum;
use App\Enums\UserIdentityEnum;
use App\Enums\UserSexEnum;
use Illuminate\Http\Resources\Json\JsonResource;

class UserForAdmin extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'name' => $this->name ?? $this->user->name ?? '缺失姓名',
            'phone' => $this->phone ?? $this->user->phone ?? '缺失手机号码',
            'sex' => (function () {
                $sex = $this->sex ?? $this->user->sex;
                return UserSexEnum::desc($sex);
            })(),
            'address' => $this->address,
            'birthday' => $this->birthday,
            'id_card_number' => $this->id_card_number,
            'native_place' => $this->native_place,
            'marital_status' => MaritalStatusEnum::desc($this->marital_status),
            'has_children' => $this->has_children ? '有' : '无',
            'education' => EducationEnum::desc($this->education),
            'residence_place' => $this->residence_place,
            'come_beijing_time' => $this->come_beijing_time,
            'now_address' => $this->now_address,
            'company_name' => $this->company_name,
            'industry' => $this->industryEnum->title ?? '未知',
            'urgent_people' => $this->urgent_people,
            'urgent_people_phone' => $this->urgent_people_phone,
            'has_contribution' => $this->has_contribution ? '有' : '无',
            //'contribution' => $this->contribution,
            'has_violated' => $this->has_violated ? '有' : '无',
            //'violated_detail' => $this->violated_detail,
            'identity' => UserIdentityEnum::desc($this->identity),
        ];
    }
}
